# 导入
import tkinter as tk
import time
import pyperclip as ppc
import re

# 创建窗口
root = tk.Tk()
root.title("tk")

# 设置稍后改变Entry（t）的变量
e = tk.StringVar()

# 创建输入框
t = tk.Entry(root, show=None, textvariable=e)
t.pack()

# 输出函数、按钮
def PrintEntry():
    print(t.get())
p = tk.Button(
    root,
    width=10,
    text="打印",
    command=PrintEntry
)
p.pack()

# 清空函数、按钮
def No():
    e.set("")
q = tk.Button(
    root,
    width=10,
    text="清空",
    command=No
)
q.pack()

# 故事生成
def Story():
    e.set("Are you a sha zi?")

story = tk.Button(
    root,
    width=10,
    text="故事生成",
    command=Story
)
story.pack()

# 复制
def Copy():
    ppc.copy(e.get())
copy = tk.Button(
    root,
    width=10,
    text="复制",
    command=Copy
)
copy.pack()

# 粘帖
def Paste():
    e.set(ppc.paste())
paste = tk.Button(
    root,
    width=10,
    text="粘帖",
    command=Paste
)
paste.pack()

# 检测是否为手机号码
def CheckPhionNumber():
    r = re.compile(r"\d" * 11)
    print(len(re.findall(r, e.get())) != 0)
    # if len(e.get()) == 12:
    #     for i in e.get():
    #         if i not in [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]:
    #             print("False")
    #             return
    #     print("True")
check = tk.Button(
    root,
    width=10,
    text="测试手机号码",
    command=CheckPhionNumber
)
check.pack()

# 算数
def Calculate(a, op, b):
    if op == "+":
        return a + b
    elif op == "-":
        return a - b
    elif op == "*":
        return a * b
    elif op == "/":
        return a / b
    elif op == "**":
        return a ** b
    elif op == "//":
        return a // b
def CheckNumber(strs):
    try:
        int(strs)
    except:
        return False
    else:
        return int(strs)
def InputNumber(strs):
    s = strs.split(" ")
    return s[0], s[1], s[2]
def Cal():
    try:
        a, op, b = InputNumber(e.get())
    except:
        print("What?")
        return
    a = CheckNumber(a)
    b = CheckNumber(b)
    re = Calculate(a, op, b)
    print(re)
calculate = tk.Button(
    root,
    width=10,
    text="简单计算",
    command=Cal
)
calculate.pack()

# 持续运行
tk.mainloop()